package com.tiny.mirror.service.product.domain.ability.service;

import com.tiny.mirror.basic.db.domain.Aggregate;
import com.tiny.mirror.basic.db.domain.AggregateFactory;
import com.tiny.mirror.service.product.domain.ability.Ability;
import com.tiny.mirror.service.product.domain.ability.repository.AbilityRepository;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;

/**
 * @Author: liujsh
 * @Description:
 * @Date: Create in 2023/9/25
 */
@Service
public class AbilityDomainService {

  @Resource
  private AbilityRepository abilityRepository;

  public Long create(Ability ability) {
    Aggregate<Ability> abilityAggregate = AggregateFactory.createEmptyAggregate();
    abilityAggregate.superAdd(ability);
    return abilityRepository.save(abilityAggregate).getRoot().getId();
  }

  public void update(Long id, Ability ability) {
    Aggregate<Ability> abilityAggregate = abilityRepository.findById(id);
    abilityAggregate.getRoot().edit(ability);
    abilityRepository.save(abilityAggregate);
  }

  public void delete(Long id) {
    Aggregate<Ability> abilityAggregate = abilityRepository.findById(id);
    abilityAggregate.delete();
    abilityRepository.save(abilityAggregate);
  }
}
